/*
 * geliftcp.h
 *
 *  Created on: 2011-10-21
 *  Author    : gelif(admin@gelif.net)
 */
#ifndef GELIFTCP_H_
#define GELIFTCP_H_

#include "geliframe.h"
#include "gelifglcanvas.h"
#include <wx/sckipc.h>

class TCPConnection: public wxTCPConnection
{
public:
    TCPConnection(GeliFrame *geliFrame = NULL);
    virtual ~TCPConnection();
    virtual bool Poke(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
    virtual bool OnPoke(const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format);
    virtual bool OnDisconnect();

    void sendBoard();
    void sendServerList();
    GeliFrame *geliFrame;
};

class TCPClient: public wxTCPClient
{
public:
    TCPClient(GeliFrame *geliFrame);
    ~TCPClient();

    bool connect(const wxString& host, const wxString& service, const wxString& topic);
    void disconnect();
    void pokeServer(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);

    wxConnectionBase *OnMakeConnection();

    TCPConnection *connection;
    GeliFrame *geliFrame;
};

class TCPServer: public wxTCPServer
{
public:
    TCPServer(GeliFrame *geliFrame);
    ~TCPServer();

    void updateClient();
    void disconnect();
    //void sendServerList();
    void pokeClient(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);

    wxConnectionBase *OnAcceptConnection(const wxString& topic);
    TCPConnection *connection;
    GeliFrame *geliFrame;
};

#endif
